import { Component, OnInit } from '@angular/core';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
import { CommonModule } from '@angular/common';
import { TableModule } from 'primeng/table';
import { ButtonModule } from 'primeng/button';

@Component({
  selector: 'app-order-select-dialog',
  standalone: true,
  imports: [
    CommonModule,
    TableModule,
    ButtonModule
  ],
  templateUrl: './order-select-dialog.component.html',
  styleUrls: ['./order-select-dialog.component.scss']
})
export class OrderSelectDialogComponent implements OnInit {
  orders: any[] = [];
  selectedOrder: any;

  constructor(
    public ref: DynamicDialogRef,
    public config: DynamicDialogConfig
  ) {}

  ngOnInit() {
    if (this.config.data?.orders) {
      this.orders = this.config.data.orders;
      console.log('Received orders:', this.orders);
    }
  }

  confirm() {
    if (this.selectedOrder) {
      console.log('Selected order:', this.selectedOrder);
      this.ref.close(this.selectedOrder);
    }
  }

  close() {
    this.ref.close();
  }
}